/*底部导航*/
$('.weui-tabbar').html(
    '<form id="_form1" method="post" action="/index/home"  class="weui-tabbar__item weui-bar__item--on">' +
    '<input type="hidden" name="token" value=' + localStorage.getItem('token') + ' /> ' +
    '<a href="javascript:;"  onclick="document.getElementById(\'_form1\').submit();">' +
    '   <div class="weui-tabbar__icon">' +
    '       <img src="/static/images/footMenu/首页.png" alt="">' +
    '   </div>' +
    '   <p class="weui-tabbar__label" style="font-size: 12px">首页</p>' +
    '</a>' +
    '</form>' +
    '<form id="_form2" method="post" action="/orderSkip/orderInfo"  class=" weui-tabbar__item">' +
    '<input type="hidden" name="token" value=' + localStorage.getItem('token') + ' /> ' +
    '<a href="javascript:;" onclick="document.getElementById(\'_form2\').submit();" >' +
    '   <div class="weui-tabbar__icon">' +
    '       <img src="/static/images/footMenu/订单.png" alt="">' +
    '   </div>' +
    '   <p class="weui-tabbar__label" style="font-size: 12px">订单</p>' +
    '</a>' +
    '</form>' +
    '<form id="_form3" method="post" action="/myPage/info"  class=" weui-tabbar__item">' +
    '<input type="hidden" name="token" value=' + localStorage.getItem('token') + ' /> ' +
    '<a href="javascript:;" onclick="document.getElementById(\'_form3\').submit();">' +
    '   <div class="weui-tabbar__icon">' +
    '       <img src="/static/images/footMenu/我的.png"  id="tabbarMy" alt="">' +
    '   </div>' +
    '   <p class="weui-tabbar__label" style="font-size: 12px">我的</p>' +
    '</a>' +
    '</form>'
)

$('.token').val(localStorage.getItem('token'));


/*正则表达式*/
/**
 * object 输入框对象
 * inputHintObj 输入框提示信息对象
 * message 提示信息
 * regex 正则
 */
function judge(inputObj, inputHintObj, message, regex) {
    //获取输入的信息
    var value = inputObj.val();
    //判断
    if (regex.test(value)) {
        inputObj.removeClass('form-control-red');
        inputHintObj.text("");
        return true;
    } else {
        inputObj.addClass('form-control-red');
        inputHintObj.text(message);

        return false;
    }
}

/*自定义提示表达式*/
/**
 * object 输入框对象
 * inputHintObj 输入框提示信息对象
 * message 提示信息
 * flog 是否显示
 */
function judgeByLoginName(inputObj, inputHintObj, message, flog) {
    //判断
    if (flog) {
        inputObj.removeClass('form-control-red');
        inputHintObj.text("");
        return true;
    } else {
        inputObj.addClass('form-control-red');
        inputHintObj.text(message);
        return false;
    }

}

/**
 * 进行验证
 */
function initAjax(url, type, data, dataType, success) {
    $.ajax({
        /*请求头 传递token 后台进行验证*/
        headers: {
            token: localStorage.getItem('token')
        },
        url: url,
        type: type,
        data: data,
        dataType: dataType,
        success: function (result) {
            if (result.code === 200) {
                //执行方法
                success(result);
            } else {

            }
        },
        error: function (result) {
            //报错调用
            location = "/index/404";
        }
    })
}

function initToken(fun, href) {
    $.ajax({
        /*请求头 传递token 后台进行验证*/
        headers: {
            token: localStorage.getItem('token')
        },
        url: '/index/inspection',
        type: 'get',
        dataType: 'json',
        success: function (result) {
            if (result.code == 200) {
                fun();
            } else {
                if (href != null) {
                    $.toast("请先登录账户", "forbidden");
                    location = href;
                }
            }
        }
    })
}

function ajaxBase(url, type, data, dataType, success) {
    $.ajax({
        url: url,
        type: type,
        data: data,
        dataType: dataType,
        success: function (result) {
            //执行方法
            success(result);
        },
        error: function (result) {
            //报错调用
            location = "/index/404";
        }
    })
}

/*唯一标识*/
function get_uuid() {
    var s = [];
    var hexDigits = "StarOrange202154";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

function get_uuidTow() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
